package cn.schoolwow.quickdao.module.database.dml.existQuery.service;

import cn.schoolwow.quickdao.domain.database.dml.UpdateType;
import cn.schoolwow.quickdao.module.database.dml.existQuery.flow.common.GetCountByUniqueFieldNamesFlow;
import cn.schoolwow.quickdao.module.database.dml.existQuery.flow.common.GetCountByUniqueKeyFlow;
import cn.schoolwow.quickdao.module.database.dml.existQuery.flow.instance.GetInstanceCountByIdFlow;
import cn.schoolwow.quickdao.module.database.dml.instance.flow.common.SetInstanceEntityFlow;
import cn.schoolwow.quickdao.module.database.dml.instance.flow.common.SetInstanceUniqueTypeFlow;
import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;

public class GetInstanceCountFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        flowContext.executeFlowList(new SetInstanceEntityFlow(), new SetInstanceUniqueTypeFlow());

        UpdateType updateType = flowContext.checkInstanceData(UpdateType.class);
        switch (updateType){
            case UpdateByUniqueFieldName:{
                flowContext.executeFlowList(new GetCountByUniqueFieldNamesFlow());
            }break;
            case UpdateByUniqueKey:{
                flowContext.executeFlowList(new GetCountByUniqueKeyFlow());
            }break;
            case UpdateById:{
                flowContext.executeFlowList(new GetInstanceCountByIdFlow());
            }break;
        }
    }

    @Override
    public String name() {
        return "获取实例在数据库中的个数";
    }
}
